<template>
    <my-form label-width="80px" v-model="form" @submit="submitHandler" @cancle="$emit('cancle')">

        <el-form-item label="上传资料：" class="group-title" label-width="94px">
            <div class="file-limit">
                1.上传PDF格式&nbsp;&nbsp;小于100M文件
            </div>
        </el-form-item>

        <el-form-item label="投标文件">
            <upload-s ref="tbFile" single :filesize="100" filetype=".pdf" :fileguid="form.fileguid" :extra="{typecode: 'tbwj', fjtype: 'tbwj',}"
                isShowIcon></upload-s>
        </el-form-item>

        <el-form-item label="招标文件">
            <upload-s ref="zbFile" single :filesize="100" filetype=".pdf" :fileguid="form.zbwjfileguid" :extra="{typecode: 'zbwj', fjtype: 'zbwj',}"
                isShowIcon></upload-s>
        </el-form-item>

        <el-form-item label="澄清文件：" class="group-title" label-width="94px">
            <div class="file-limit">
                如有澄清文件/补遗文件，请上传完整，以免影响标书检查结果
            </div>
        </el-form-item>

        <el-form-item label="澄清文件">
            <upload-s ref="cqFile" single :filesize="100" filetype=".pdf" :fileguid="form.cqwjfileguid" :extra="{typecode: 'cqwj', fjtype: 'cqwj',}"
                isShowIcon></upload-s>
        </el-form-item>

        <el-form-item label="补遗文件">
            <upload-s ref="byFile" :limit="6" :filesize="100" filetype=".pdf" :fileguid="form.bywjfileguid" :extra="{typecode: 'bywj', fjtype: 'bywj',}"
                isShowIcon></upload-s>
        </el-form-item>

        <template slot="btn" slot-scope="scope">
            <el-button type="primary" size="large" @click="scope.submitHandler">
                提交
            </el-button>

            <el-button size="large" @click="scope.cancleHandler">
                取消
            </el-button>
        </template>
    </my-form>
</template>

<script>
import UploadS from '../../../components/upload-s/index.vue';

export default {
    components: {
        UploadS,
    },
    props: {
        data: {
            type: Object,
            default: () => ({}),
        },
    },
    data() {
        return {
            form: {},
        };
    },
    methods: {
        submitHandler() {
            if (!this.$refs.tbFile.exist) {
                showMsgBox('请上传投标文件', 'error');

                return;
            }

            if (!this.$refs.zbFile.exist) {
                showMsgBox('请上传招标文件', 'error');

                return;
            }

            var { cqwjfileguid, bywjfileguid, ...paramData } = this.form;

            if (this.$refs.cqFile.exist) {
                paramData.cqwjfileguid = cqwjfileguid;
            }
            if (this.$refs.byFile.exist) {
                paramData.bywjfileguid = bywjfileguid;
            }

            this.$post(`${this.$store.state.api.webUrl}/tbfile/check/add.json`, paramData, (data) => {
                this.$emit('update');
            });
        },
        initHandler() {
            this.$get(
                `${this.$store.state.api.webUrl}/tbfile/check/detail.json`,
                {
                    rowguid: this.data.rowguid,
                },
                (data) => {
                    this.form = data;
                }
            );
        },
    },
    mounted() {
        this.initHandler();
    },
};
</script>

<style lang="scss" scoped>
@import '@css/var.scss';

::v-deep .group-title {
    .el-form-item__label {
        font-size: 16px;
        font-weight: 600;
    }
}
</style>